#pragma once
#include <cstddef>
#include<iostream>
#include<string.h>
#include <string>

namespace ns_protocol
{
#define SPACE " "
#define SPACE_LEN strlen(SPACE)
#define SEP "\r\n"
#define SEP_LEN strlen(SEP)

    class Request
    {
    public:
        std::string Serialize()
        {
            std::string str;
            str=std::to_string(_x);
            str+=SPACE;
            str+=std::to_string(_y);
            return str;
        }
        bool Deserialize(const std::string str)
        {
            return true;
        }
    public:
        Request(int x,int y,char op)
        :_x(x),_y(y)
        ,_op(op)
        {

        }
        ~Request(){}
        int _x;
        int _y;
        char _op;
    };

    class Response
    {
    public:
        std::string Serialize()
        {
            std::string str;
            str=std::to_string(_code);
            str+=SPACE;
            str+=std::to_string(_result);
            return str;
        }
        bool Deserialize(const std::string str)
        {
            std::size_t pos=str.find(SPACE);
            if(pos==std::string::npos){
                return false;
            }
            _code=atoi(str.substr(0,pos).c_str());
            _result=atoi(str.substr(pos+SPACE_LEN).c_str());
            return true;
        }
    public:
        Response(int result,int code,int x,int y,char op)
        :_result(result),_code(code)
        ,_x(x),_y(y),_op(op)
        {

        }
        ~Response()
        {

        }
        int _code;
        int _result;
        int _x;
        int _y;
        char _op;
    };
}
